<template>
  <back-btn></back-btn>
  <div id="app">
    <input type="text" placeholder="正常input" />
    <input type="text" ref="focusIpt" placeholder="自动聚焦" />
  </div>
</template>

<script lang="ts">
import { defineComponent, onMounted, ref } from "vue";

export default defineComponent({
  setup() {
    const focusIpt = ref<HTMLElement | null>(null);

    // 在setup执行时，template中的元素还没挂载到页面上，所以必须在mounted之后才能获取到元素。
    onMounted(() => {
      focusIpt.value?.focus();
    });

    return { focusIpt };
  },
});
</script>

<style scoped></style>
